<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%common_log}}`.
 */
class m190430_032610_create_common_log_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%common_log}}', [
            'id' => $this->primaryKey(),
            'member_id' => $this->integer()->defaultValue(0)->comment('用户id'),
            'method' => $this->string(20)->defaultValue('')->comment('提交类型'),
            'module' => $this->string(50)->defaultValue('')->comment('模块'),
            'controller' => $this->string(50)->defaultValue('')->comment('控制器'),
            'action' => $this->string(50)->defaultValue('')->comment('方法'),
            'url' => $this->string(1000)->defaultValue('')->comment('提交url'),
            'get_data' => $this->text()->comment('get 数据'),
            'post_data' => $this->text()->comment('post 数据'),
            'ip' => $this->string(20)->defaultValue('')->comment('ip地址'),
            'error_code' => $this->integer()->defaultValue(0)->comment('错误码'),
            'error_msg' => $this->string(200)->defaultValue('')->comment('错误信息'),
            'error_data' => $this->text()->comment('错误日志'),
            'req_id' => $this->string(50)->defaultValue('')->comment('对外ID'),
            'status' => $this->tinyInteger(4)->notNull()->defaultValue(1)->comment('状态'),
            'created_at' => $this->integer()->defaultValue(0)->comment('创建时间'),
            'updated_at' => $this->integer()->defaultValue(0)->comment('更新时间'),
        ]);
        $this->createIndex('idx_error_code','{{%common_log}}', 'error_code', 0);
        $this->createIndex('idx_req_id', '{{%common_log}}', 'req_id', 0);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('{{%common_log}}');
    }
}
